# -*- coding:UTF-8 -*-
"""
@Project : SeleniumAutoTest
@File    : example2.py
@IDE     : PyCharm
@Author  : WorldWind(1772830365@qq.com)
@Address : China - HeiLongjiang - Herbin
@Date    : 2025/8/3 上午11:17
"""
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

service = Service("D:\chromedriver-win64\chromedriver.exe")  # 配置chromedriver文件
dr = webdriver.Chrome(service=service)
dr.maximize_window()
dr.get("https://www.baidu.com")
sleep(2)
dr.find_element('id', 'kw').send_keys('黑神话悟空')
sleep(2)
dr.find_element(By.ID, 'su').click()
sleep(2)
dr.execute_script('window.scrollTo(0,document.body.scrollHeight)')  # 滚动屏幕
waitObj = WebDriverWait(dr, 30, 1)  # 定义显示等待对象
# waitObj.until(lambda x: dr.find_element(By.XPATH, '//*[@id="page"]/div/a[1]/span'))
# dr.find_element(By.XPATH, '//*[@id="page"]/div/a[1]/span').click()
waitObj.until(EC.presence_of_element_located((By.XPATH, '//*[@id="page"]/div/a[1]/span')))
dr.find_element(By.XPATH, '//*[@id="page"]/div/a[1]/span').click()
sleep(30)
